package com.weilele.leisure.video_factory.ui.module.sniff


import android.os.Bundle
import android.view.WindowManager
import androidx.fragment.app.Fragment
import com.weilele.base.library.BaseBindingFragment
import com.weilele.base.library.FragmentContainerActivity
import com.weilele.leisure.time.databinding.FragmentSniffBinding
import com.weilele.mvvm.base.livedata.appCompatActivity
import com.weilele.mvvm.utils.activity.hiddenKeyboard
import com.weilele.mvvm.utils.android_r.ImeHelper


class SniffFragment : BaseBindingFragment<FragmentSniffBinding>() {
    companion object {
        fun start(fragment: Fragment) {
            FragmentContainerActivity.start<SniffFragment>(fragment)
        }
    }

    private val imeHelper by lazy {
        ImeHelper(this, enableOnApplyWindowInsetsListener = false)
    }

    override fun initUi(savedInstanceState: Bundle?) {
        super.initUi(savedInstanceState)
        imeHelper.setOnImeListener { imeOffset, imeHeight ->
            if (imeHeight > 0) {
                //显示键盘
                val offY = mBinding.root.height - mBinding.etInput.bottom - imeHeight
                if (offY > 0) {
                    val r = imeOffset.toFloat() / imeHeight
                    mBinding.etInput.translationY = offY * r
                }
            }
        }
    }

    override fun onStop() {
        super.onStop()
        appCompatActivity?.hiddenKeyboard()
        mBinding.etInput.translationY = 0f
    }
}